﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Softyum.Common.OS;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Softyum.ForexAgent
{
    [StructLayout(LayoutKind.Sequential)]
    public struct NEWNEWS
    {
        [MarshalAs(UnmanagedType.LPTStr)]
        public string szTitle;
        [MarshalAs(UnmanagedType.LPTStr)]
        public string szText;
    }

    public static class CustomMessages
    {
        public const UInt32 NewNews = SendMessageApi.WM_USER + 100;

        public static void SendNewNews(IntPtr hWnd, string title, string text)
        {
            NEWNEWS nn = new NEWNEWS();
            nn.szTitle = title;
            nn.szText = text;
            IntPtr lParam = Marshal.AllocHGlobal(Marshal.SizeOf(nn));
            Marshal.StructureToPtr(nn, lParam, false);
            SendMessageApi.SendMessage(hWnd, NewNews, IntPtr.Zero, lParam);
        }

        public static NEWNEWS GetNewNewsParams(Message m)
        {
            NEWNEWS param = (NEWNEWS)Marshal.PtrToStructure(m.LParam, typeof(NEWNEWS));
            Marshal.FreeHGlobal(m.LParam);
            return param;
        }
    }
}
